package com.eke.serviceimpl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.eke.bean.Comment;
import com.eke.dao.CommentDao;
import com.eke.service.CommentService;

@Service
public class CommentServiceImpl implements CommentService {

	@Resource
	private CommentDao commentDao;

	/**
	 * 查询文章评论总数
	 * 
	 * @param articleId
	 *            文章Id
	 * @return int
	 */
	public int queryArticleCommentTotal(Integer articleId) {
		// TODO Auto-generated method stub
		return commentDao.queryArticleCommentTotal(articleId);
	}

	/**
	 * 查询文章评论
	 * 
	 * @param articleId
	 *            文章id
	 * @param startRow
	 *            起始页码
	 * @param pageSize
	 *            每页数据
	 * @return List<{@link Comment}>
	 */
	public List<Comment> queryArticleComment(Integer articleId, int startRow, int pageSize) {
		// TODO Auto-generated method stub
		return commentDao.qurryArticleComment(articleId, startRow, pageSize);
	}

	/**
	 * 添加文章评论
	 * 
	 * @param comment
	 *            评论对象
	 * @return {@link Boolean}
	 */
	
	public boolean addArticleComment(Comment comment) {
		// TODO Auto-generated method stub
		if (comment.getUserId() == null) {
			return false;
		} else {
			return (commentDao.insert(comment) > 0);
		}
	}

	/**
	 * 查询评论的回复
	 * 
	 * @return List<{@link Comment}>
	 */
	public List<Comment> qurryCommentRq(int commentId, int startRow, int pageSize) {
		return commentDao.qurryCommentRq(commentId, startRow, pageSize);
	}

	/**
	 * 点赞
	 * 
	 * @param commentId
	 *            评论id
	 * @return int
	 * 
	 */
	public boolean goodNumber(int commentId) {
		if (commentDao.goodNumber(commentId) > 0) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 点踩
	 * 
	 * @param commentId
	 *            评论id
	 * @return int
	 */
	public boolean badNumber(int commentId) {
		if (commentDao.badNumber(commentId) > 0) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 添加评论的回复
	 * 
	 * @return int
	 */
	public boolean addCommentRq(Comment comment) {
		if (commentDao.addCommentRq(comment) > 0) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 查询文章评论总数
	 * 
	 * @return int
	 */
	public int queryCommentRqTotal(int commentId) {
		// TODO Auto-generated method stub
		return commentDao.queryCommentRqTotal(commentId);
	}

	/**
	 * 更改评论状态为采纳
	 * 
	 * @param commentId
	 * @return {@link Boolean} true 成功 false 失败
	 */
	
	public boolean updateCommentState(int commentId) {
		// TODO Auto-generated method stub
		return commentDao.updateCommentState(commentId);
	}

	/**
	 * 评论被采纳后，增加积分
	 * 
	 * @param interal
	 *            积分数量
	 * @param commentUserId
	 *            评论用户id
	 * @return {@link Boolean} true 增加成功 false 增加失败
	 */
	
	public boolean addInteral(int interal, int commentUserId) {
		// TODO Auto-generated method stub
		return commentDao.addInteral(interal, commentUserId);
	}

}
